package com.atguigu.staservice.schedule;

import com.atguigu.staservice.service.StatisticsDailyService;
import com.atguigu.staservice.utils.DateUtil;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * create by: zr
 * description: TODO
 * create time: 2021/11/26 22:19
 * 定时任务
 *
 * @author 76109
 * @Param: null
 * @return
 */
@Component
public class ScheduledTask {
    @Resource
    private StatisticsDailyService statisticsDailyService;

    /**
     * 在每天的凌晨一天  把前一天的数据进行查询 并添加
     */
    @Scheduled(cron = "0 0 1 * * ? ")
    public void task() {
        statisticsDailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
